import peewee_async
import tornado.web
from tornado import httpserver

from db import database,TestNameModel


from base import BaseHandler

# Define handlers
class RootHandler(BaseHandler):
    """
    Accepts GET methods.
    GET: get instance by id, `id` argument is required
    """
    async def put(self):

        obj_id = self.get_argument('id', None)

        print("参数是",obj_id)

        return self.write({"code":200,"msg":"helloworld"})


        try:
            obj = await self.application.objects.get(TestNameModel, id=obj_id)
            print(obj)
            print("123")
            self.write({
                'id': 121,
                'name': obj.name,
            })
        except TestNameModel.DoesNotExist:
            raise tornado.web.HTTPError(404, "Object not found!")


def main():
    app = tornado.web.Application(handlers=[
        (r'/', 'my.RootHandler'),
        (r'/ss/', 'my.RootHandler'),

         ], debug=True)

    # Set up database and manager
    app.objects = peewee_async.Manager(database)

    server = httpserver.HTTPServer(app, xheaders=True)
    server.listen(8000)
    tornado.ioloop.IOLoop.instance().start()


if __name__ == '__main__':
    main()